import requests
import json
from comm.module import *
#from comm.LogUtils import logger
#from comm.postgresutility import postsql_utility
import datetime
import hashlib

# 获取课程考勤记录
def doGetcabinetList():
   try:
    
      timestamp = int((datetime.datetime.now().timestamp())* 1000)
      print(timestamp)
      #timestamp = (currenttime.timestamp() * 1000)
      #print("时间："+timestamp)

      temp_appId = "E2B67E85-0864-4B35-9AEE-DF80BD27CA3C"
      temp_key   = "959C778C-9D6F-47FB-A847-233E46414E22"

      #sign 签名 生成方式:md5(时间戳+appId+秘钥)
      temp_data = str(timestamp)+str(temp_appId)+str(temp_key)
      print(temp_data)
      md5 = hashlib.md5()  # 创建一个md5对象
      md5.update(temp_data.encode('utf-8'))  # 使用utf-8编码数据
      temp_sign = md5.hexdigest()  # 返回加密后的十六进制字符串

      print("sign:"+temp_sign)

      #temp_date = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")   # '2023-03-29 20:11:42'
      temp_date = datetime.datetime.now().strftime("%Y-%m-%d")+" 00:00:01"
      print(temp_date)

      temp_url = "http://go-pro.gz-gohi.com/go-pro-admin/api/admin/link"
      #httpconn = http.client.HTTPSConnection(temp_url)
      payload = json.dumps({
         "timestamp": timestamp,
         "appId": temp_appId,
         "sign": temp_sign,
         "data": {
               "current": 1,
               "size": 200,
               "updateTime": temp_date
            }
         })
      headers = {
         'Content-Type': 'application/json'
      }
      response = requests.request("POST", temp_url+"/atnd/course/log/v1", headers=headers, data = payload)
      #res = response.text.encode('utf8')
      data = response.json()
      #data = data.decode("utf-8")
      print(data)
      #logger.info('141:' + data.decode("utf-8"))
      response.close()

      #json_str = json.loads(data)
      #ierrCode = json_str["errCode"]
   except Exception as e:
      print(str(e))

#
doGetcabinetList()